#ifndef __TR_R2_HPP__
#define __TR_R2_HPP__

#include "../../tdp2/tdp2_math.hpp"
#include "../../tdp2/tdp2_string.hpp"
#include "../../tdp2/tdp2_husk.hpp"
#include "../../tdp2/tdp2_maincontext.hpp"

namespace TDP
{
	class terSkeletonAsset;
	class terMeshGroupAsset;
	class terAssembledModelAsset;

	class MainContext;
	class PanicHandler;
};

namespace RDX
{
	struct OperationContext;
}

struct r2_model_t
{
	TDP::CString meshLocation;
	TDP::CString skelLocation;
};


extern	TDP::Containers::Husk<TDP::MainContext>			r_mctx;

void		R2_ClearScene( void );
void		R2_AddRefEntityToScene( const refEntity_t *ent );
void		R2_AddPolyToScene( qhandle_t hShader , int numVerts, const polyVert_t *verts, int num );
void		R2_AddLightToScene( const vec3_t org, float intensity, float r, float g, float b );
void		R2_AddAdditiveLightToScene( const vec3_t org, float intensity, float r, float g, float b );
void		R2_RenderScene( const refdef_t *fd );

void		R2_StretchRaw (int x, int y, int w, int h, int cols, int rows, const byte *data, int client, qboolean dirty);
void		R2_UploadCinematic (int w, int h, int cols, int rows, const byte *data, int client, qboolean dirty);


void		R2_BeginRegistration( glconfig_t *glconfig );
void		R2_LoadWorldMap( const char *mapname );
void		R2_SetWorldVisData( const byte *vis );
qhandle_t	R2_RegisterModel( const char *meshName, const char *skelName );
qhandle_t	R2_RegisterSkin( const char *name );
void		R2_Shutdown( qboolean destroyWindow );
void		R2_ShutdownTBR();

qhandle_t	R2_RegisterShader( const TDP::PanicHandler *ph, const char *name );
qhandle_t	R2_RegisterShaderNoMip( const TDP::PanicHandler *ph, const char *name );
qhandle_t	R2_RegisterShaderFromImage(const char *name, int lightmapIndex, image_t *image, qboolean mipRawImage);
void		R2_ShutdownShaders();

void		*R2_ModelFromHandle( qhandle_t h );
void		R2_ShutdownModels();

void		R2_EndRegistration( void );

void		R2_SetColor( const float *rgba );
void		R2_StretchPic ( float x, float y, float w, float h, 
					  float s1, float t1, float s2, float t2, qhandle_t hShader );

void		R2_EndFrame( int *frontEndMsec, int *backEndMsec );

int			R2_MarkFragments( int numPoints, const vec3_t *points, const vec3_t projection,
				   int maxPoints, vec3_t pointBuffer, int maxFragments, markFragment_t *fragmentBuffer );
int			R2_LerpTag( orientation_t *tag, qhandle_t handle, int startFrame, int endFrame, 
					 float frac, const char *tagName );
void		R2_ModelBounds( qhandle_t handle, vec3_t mins, vec3_t maxs );
int			R2_LightForPoint( vec3_t point, vec3_t ambientLight, vec3_t directedLight, vec3_t lightDir );
void		R2_RegisterFont(const char *fontName, int pointSize, fontInfo_t *font);
void		R2_RemapShader(const char *oldShader, const char *newShader, const char *timeOffset);
qboolean	R2_GetEntityToken( char *buffer, int size );
qboolean	R2_inPVS( const vec3_t p1, const vec3_t p2 );
void		R2_BeginFrame( stereoFrame_t stereoFrame );

void		R2_InitTBR();

void		R2_WaitForLoader();

void		*R2_ShaderFromHandle( qhandle_t h );
void		R2_FatalError( RDX::OperationContext *ctx );

#endif

